<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>维修单管理</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <link rel="stylesheet" href="css/base.css">
    <link rel="stylesheet" href="../css/element-ui.css" />
    <link rel="stylesheet" href="css/repairBillManager.css">
    <!--[if lt IE 9]>
    <link rel="stylesheet" href="../css/pages/ie8.css"/>
    <script src="../js/common/html5shiv.min.js"></script>
    <script src="../js/common/respond.min.js"></script>
    <script src="../js/common/es5-shim.min.js"></script>
    <![endif]-->
    <script src="js/babel.min.js"></script>
    <script src="../js/common/jquery.min.js"></script>
    <script src="../js/common/vue.js"></script>
    <script src="../js/common/element-ui.js"></script>
 
</head>
<body>
<div id="repair-manager">
	<div class="repair-items">
	    <div class="repair-item"  @click="edit">
	        <span class="ic-repair ic-edit" ></span><br/><span class="text" >编辑</span>
	    </div>
	    <div class="repair-item"  @click="refresh" >
	        <span class="ic-repair ic-refresh"></span><br/><span class="text" >刷新</span>
	    </div>
	    <div class="repair-item" style="float:right" @click="back">
       	 <span class="ic-repair ic-back"></span>
   		 </div>
	</div>
<div class="container">
    <div class="repair-header">
        <div class="repair-title"><span class="title">维修单管理</span></div>
        <div class="repair-content">
	        <table>
	            <tr>
	                <td>
	                    <div class="wrapper">
	                      <span class="text">帐户名称:</span>
	                      <div class="fill"><span class="value">{{DeptAccountName}}</span></div>
	                    </div>
	                </td>
	                <td>
	                    <div class="wrapper"><span class="text">起始时间：</span>
	                        <div class="fill">
		                        <div class="block">
								    <el-date-picker
								      v-model="inputTimeStart"
								      type="datetime"
								      format="yyyy-MM-dd HH:mm:ss"
								      placeholder="选择起始时间">
								    </el-date-picker>
								  </div>
	                        
	                       <!--  <input type="text" class="disabled forbid" @click="dateStart" v-model="inputTimeStart"> --></div>
	                    </div>
	                </td>
	                <td>
	                    <div class="wrapper"><span class="text">发票号：</span>
	                        <div class="fill"><input class="disabled forbid" type="text" v-model="InvoiceNumber"></div>
	                    </div>
	                </td>
	            </tr>
	            <tr>
	             	<td>
	                    <div class="wrapper"><span class="text">科室名称：</span>
	                      <div class="fill"><span class="value">{{DeptName}}</span></div>
	                    </div>
	                    
	                </td>
	                <td>
	                    <div class="wrapper"><span class="text">结束时间：</span>
	                        <div class="fill">
	                        <div class="block">
								    <el-date-picker
								      v-model="inputTimeEnd"
								     type="datetime"
								      format="yyyy-MM-dd HH:mm:ss"
								      placeholder="选择结束时间">
								    </el-date-picker>
								  </div>
	                        </div>
	                    </div>
	                </td>
	                <td>
	                    <div class="wrapper"><span class="text">卡片号：</span>
	                        <div class="fill"><input class="disabled forbid"  type="text" v-model="CardNumber"></div>
	                    </div>
	                </td>
	            </tr>
	            <tr>
	                <td>
	                    <div class="wrapper"><span class="text">账册名称：</span>
	                        <div class="fill">
		                        <select style="width:100%;height:20px;line-height:20px;font-size:12px;color: darkslategrey;" v-model="GoodsBookID" >
									  <option v-for="v in GoodsBookNames" :value ="v.value">{{v.name}}</option>
								</select>
	                        </div>
	                    </div>
	                </td>
	            </tr>
	        </table>
   		 </div>
    </div>
    <div class="repair-middle">
    	<div class="content">
           <table class="repair-list">
            	<tr style="background-color: #ddd;">
                  <th v-for="(data,index) in tableData"><p @click='reverse(index)'>{{data}}<i v-if="index==7" class="el-icon-d-caret"></i></p></th>
                 </tr>
                <tr :class="{active:active==index}" v-if="repairBillData.length"  v-for="(v,index) in repairBillData"  @click="check(index,v.BillSN)"  @dblclick="href(v.BillSN)" >
                    <td><p>{{v.BillSN}}</p></td>
                    <td><p>{{v.StatusStr=='lr'?'录入':v.StatusStr=='ys'?'验收':v.StatusStr=='zf'?'作废':v.StatusStr=='dz'?'登账':''}}</p></td>
                    <td><p>{{v.InvoiceNumber}}</p></td>
                    <td><p>{{v.DeptAccountName}}</p></td>
                    <td><p>{{v.DeptName}}</p></td>
                    <td><p>{{v.SupperName}}</p></td>
                    <td><p>{{v.InputUserName}}</p></td>
                    <td><p>{{v.InputTime?v.InputTime.split('.')[0]:v.InputTime}}</p></td>
                    <td><p>{{v.CheckUserName}}</p></td>
                    <td><p>{{v.CheckTime?v.CheckTime.split('.')[0]:v.CheckTime}}</p></td>
                    <td><p>{{v.BookinUserName}}</p></td>
                    <td><p>{{v.BookinTime?v.BookinTime.split('.')[0]:v.BookinTime}}</p></td>
                    <td><p>{{v.RepairReason}}</p></td>
                    <td><p>{{v.CheckComment}}</p></td>
                    <td><p>{{v.Amount}}</p></td>
                    <td><p>{{v.SupperID}}</p></td>
                    <td><p>{{v.DeptID}}</p></td>
                    <td><p>{{v.GoodsBookID}}</p></td>
                    <td><p>{{v.DeptAccountID}}</p></td>
                    <td><p>{{v.CheckUserID}}</p></td>
                    <td><p>{{v.InputUserID}}</p></td>
                    <td><p>{{v.BookinUserID}}</p></td>
                </tr>
             </table>
         </div>
         <div class="popup" :class={popupShow:popup} >
 	 		<i class="ic-warning"></i><span class="text">{{notice}}</span>
 		</div>
    </div>
    	
    <!-- <div class="repair-footer"></div>-->
</div>
</div>

<script src="js/index.js"></script>

<script>
var app = new Vue({
	  el: '#repair-manager',
	  data: {
			 "GoodsBookNames":[{'name':'贵重医疗设备','value':'000000000000GG'},{'name':'专用设备','value':'000000000000HH'}],
			 "DeptAccountName":JSON.parse(localStorage.getItem('deptAccount')).DeptAccountName,
			 "DeptName":JSON.parse(localStorage.getItem('deptInfo')).Ksmc,
			 "DeptAccountID":JSON.parse(localStorage.getItem('deptInfo')).DeptAccountID,
			 "notice":'',
			 "popup":false,
			 "tableData":[
				 '单据号','状态','发票号','帐户名称','科室名称','维修单位','录入人','录入时间','验收人','验收时间','登帐人','登帐时间','维修理由','验收说明','金额','供应商ID','科室代码','账册ID','科室账户ID','验收员ID','录入员ID','登帐员ID'
			 ],
			 'sortFlag':false,
			 "repairBillData":[],
			 "billSN":'',
			"active":null,
			"inputTimeStart":GetPreMonthDay(new Date())||null,
			"inputTimeEnd":new Date().format("yyyy-MM-dd hh:mm:ss"),
			 "GoodsBookID":'000000000000GG',
			 "InvoiceNumber":null,
			 "CardNumber":null,
			 'startTime':null,
			 'endTime':null
	  },
	 created:function(){
		 var _this=this;
		 this._getOutDTOBillHeads(_this.inputTimeStart,_this.inputTimeEnd,_this.GoodsBookID,_this.InvoiceNumber,_this.CardNumber);
	 },
	　watch:{
		inputTimeStart:function(curVal,oldVal){
				this.startTime = (!curVal ?" ":curVal.format("yyyy-MM-dd hh:mm:ss"));
			},
		 inputTimeEnd:function(curVal,oldVal){
				this.endTime= (!curVal?" ":curVal.format("yyyy-MM-dd hh:mm:ss"))
			}
		},
	 methods:{
		 edit:function(){
			 var _this = this;
			 if(!this.billSN){
				this._popUp('请选择卡片!!') 
				return false;
			 }
			 this.href(_this.billSN);
		 },
		 refresh:function(){
			 var _this=this;
			 var inputTimeStart,inputTimeEnd;
			 if(!this.inputTimeStart){
				 this._popUp('请选择开始时间!!') 
					return false;
			 }
			 if(!this.inputTimeEnd){
				 this._popUp('请选择结束时间!!') 
					return false;
			 }
			if(typeof this.inputTimeStart == 'object' ){
				 inputTimeStart = this.startTime
			 }else inputTimeStart =this.inputTimeStart;
			 if(typeof this.inputTimeEnd == 'object' ){
				 inputTimeEnd = this.endTime
			 }else inputTimeEnd =this.inputTimeEnd;
			 if(new Date(inputTimeStart)>new Date(inputTimeEnd)){
				 this._popUp('开始时间不能大于结束时间!!') 
					return false;
			 }
			 this._getOutDTOBillHeads(inputTimeStart,inputTimeEnd,_this.GoodsBookID,_this.InvoiceNumber,_this.CardNumber);
		 },
		 reverse:function(index){
			 switch (index) {
	          case 7:
	        	  this.repairBillData.reverse()
	        	  break; 
	        }
			 
		 },
		 _popUp:function(str){
			 var _this = this;
			 this.popup=true;
			 this.notice=str;
			 var timer = setInterval(function(){
				 _this.popup=false;
				 clearInterval(timer);
			 },1000)
		 },
		 back:function(){
			 $(window.parent.document).find('#repair-bill-manager').remove();
		 },
		 check:function(index,BillSN){
				this.active = index;
				this.billSN = BillSN;
			 },
		  
		 href:function(billSN){
			 var url = getRootPath() +'repairBill/repairBill.html?billSN='+billSN;
	       	  var myElement = document.createElement("iframe")
	       	  myElement.src = url;
	       	  myElement.id ="repair-bill-container";
	       	  myElement.style.width = "100%";
	       	  myElement.style.height = "100%";
	       	  myElement.style.position = "fixed";
	       	  myElement.style.left = "0";
	       	  myElement.style.top = "0";
	       	  myElement.style.zIndex = "100";
	       	  document.body.appendChild(myElement);
		 },
		 _getOutDTOBillHeads:function(inputTimeStart,inputTimeEnd,GoodsBookID,InvoiceNumber,CardNumber){
			 var _this = this;
			 var condition={};
			 if(InvoiceNumber!==null&&InvoiceNumber!==""&&CardNumber!==null&&CardNumber!==""){
				 condition={"Conditions":[{"Conditions":[{"Conditions":[{"Conditions":[{"ColumnName":"a.InputTime","FullString":null,"Oper":"MoreOrEqual","Value":inputTimeStart,"Type":"DateTime"},{"ColumnName":"a.InputTime","FullString":null,"Oper":"Less","Value":inputTimeEnd,"Type":"DateTime"}],"Type":"AND"},{"ColumnName":"a.GoodsBookID","FullString":null,"Oper":"Equal","Value":GoodsBookID,"Type":"String"}],"Type":"AND"},{"ColumnName":"a.InvoiceNumber","FullString":null,"Oper":"Equal","Value":InvoiceNumber,"Type":"String"}],"Type":"AND"},{"ColumnName":"j.CardNumber","FullString":null,"Oper":"Equal","Value":CardNumber,"Type":"String"}],"Type":"AND"};
			 }
			 if(InvoiceNumber==null||InvoiceNumber==""){
				 if(CardNumber!==null&&CardNumber!==""){
					 condition={"Conditions": [{"Conditions": [{"Conditions": [{"ColumnName": "a.InputTime","FullString": null,"Oper": "MoreOrEqual","Value": inputTimeStart,"Type": "DateTime"}, {"ColumnName": "a.InputTime","FullString": null,"Oper": "Less","Value": inputTimeEnd,"Type": "DateTime"}],"Type": "AND"}, {"ColumnName": "a.GoodsBookID","FullString": null,"Oper": "Equal","Value": GoodsBookID,"Type": "String"}],"Type": "AND"}, {"ColumnName": "j.CardNumber","FullString": null,"Oper": "Equal","Value": CardNumber,"Type": "String"}],"Type": "AND"}
						
				 	}
				 else{
					 condition={"Conditions":[{"Conditions":[{"ColumnName":"a.InputTime","FullString":null,"Oper":"MoreOrEqual","Value":inputTimeStart,"Type":"DateTime"},{"ColumnName":"a.InputTime","FullString":null,"Oper":"Less","Value":inputTimeEnd,"Type":"DateTime"}],"Type":"AND"},{"ColumnName":"a.GoodsBookID","FullString":null,"Oper":"Equal","Value":GoodsBookID,"Type":"String"}],"Type":"AND"}
				 	}
				 }
			 if(CardNumber==null||CardNumber==""){
				if(InvoiceNumber!==null&&InvoiceNumber!==" "){
					condition={"Conditions":[{"Conditions":[{"Conditions":[{"ColumnName":"a.InputTime","FullString":null,"Oper":"MoreOrEqual","Value":inputTimeStart,"Type":"DateTime"},{"ColumnName":"a.InputTime","FullString":null,"Oper":"Less","Value":inputTimeEnd,"Type":"DateTime"}],"Type":"AND"},{"ColumnName":"a.GoodsBookID","FullString":null,"Oper":"Equal","Value":GoodsBookID,"Type":"String"}],"Type":"AND"},{"ColumnName":"a.InvoiceNumber","FullString":null,"Oper":"Equal","Value":InvoiceNumber,"Type":"String"}],"Type":"AND"}
					}
				 else{
					 condition={"Conditions":[{"Conditions":[{"ColumnName":"a.InputTime","FullString":null,"Oper":"MoreOrEqual","Value":inputTimeStart,"Type":"DateTime"},{"ColumnName":"a.InputTime","FullString":null,"Oper":"Less","Value":inputTimeEnd,"Type":"DateTime"}],"Type":"AND"},{"ColumnName":"a.GoodsBookID","FullString":null,"Oper":"Equal","Value":GoodsBookID,"Type":"String"}],"Type":"AND"}
				 	}
				 }
			 
			 var parms = {
			      		  className: 'RepairManager',
			              method: 'GetOutDTOBillHeads',
			              condition:JSON.stringify(condition)
			    	  }
			 this._fetch(parms,function(result){
				 var arrData = [];
				 result.forEach(function(item){
					 if(_this.DeptAccountID == item.DeptAccountID){
						 arrData.push(item)
						 
					 }
				 })
				 _this.repairBillData=_this.bubbleSort(arrData);;
			 })
			},
			bubbleSort:function(arr) {
			    var len = arr.length;
			    for(var i = 0; i < len; i++) {
			        for(var j = 0; j < len - 1 - i; j++) {
			          if(new Date(arr[j].InputTime.split('.')[0].replace(/-/g, "\/")) - new Date(arr[j+1].InputTime.split('.')[0].replace(/-/g, "\/"))<0) { //相邻元素两两对比
			            var temp = arr[j + 1]; //元素交换
			            arr[j + 1] = arr[j];
			            arr[j] = temp;
			          }
			        }
			    }
			    return arr;
			  }
			,
		 _fetch:function(parms,cb,failure){
			 $.ajax({
				  type: 'POST',
				  url: getRootPath()+'/api/sendPostRequest' ,
				  headers: {
					  'Accept': 'application/json',
				      'Content-Type': 'application/json'
			        },
				  data: JSON.stringify(parms),
				  success: function(res){
					  
					  if(res.issuccess==0){
						 var result = JSON.parse(res.result);
						 cb&&cb(result)
					  }else {
						  failure&&failure();
					  }
				},
				error:function(err){
					alert(err)
				}
			 });	    
		 }
	 }	 
	})
</script>

</body>
</html>